#pragma once

#include "base/StructType.hpp"
#include "common/CellCommon.hpp"
#include "base/Macro.hpp"
#include "common/FileCommon.hpp"
#include "core/page/BasePage.hpp"

class Page : public BasePage{
public:
    std::vector<std::vector<Cell>> mPageData{};

    Page(std::fstream * file,FileHeader * fileHeader,PageHead * pageHead,std::vector<FieldInfo> *fieldList,std::vector<uint8_t> *page,std::vector<uint32_t> *slot);
    Page(Context &context,const std::string& name,uint32_t &pageNo);
    int updNextOffset(uint64_t newRecordOffset,uint64_t prevRecordOffset);
    int updPrevOffset(uint64_t newRecordOffset,uint64_t nextRecordOffset);
    int insert(std::vector<Cell> &cells);

    int createPage();

    int readPageAll(uint32_t offset);

    std::pair<bool, uint32_t> findRecordIndex(uint32_t newKey) const;
    uint32_t findKey(uint32_t mid) const;

//    int getRecord(std::vector<Cell> &cells,uint32_t &offset);

    size_t vectorToCell(std::vector<Cell> &cells,uint8_t *beginMemoryAddress);

    uint32_t cellToVector(std::vector<Cell> &cells,uint8_t * beginMemoryAddress);

    int updRecordAll(std::vector<UpdateSetItem> &updateSets);

    int updRecordDeleted(uint32_t offset);
    int updRecordDeleted(std::vector<Cell> &cell);

    int saveAll();
//    Page findDataPage(std::string &table,uint32_t &pageNo,uint64_t &key);
};